/** ************************查询结果数据集**************************** */	
var dataStore = new Ext.data.JsonStore({
	url 			: path+'/servlet/MainServlet?action=getlist',
	baseParams 		: {
		ajax : true
	},
	root 			: 'list',
	totalProperty 	: 'results',  //显示总条数
	remoteSort 		: true,
	fields 			: [
		               'id','createTime','phoneNumber','email','name'
					  ]
});
//{"id":2,"createTime":1332770852792,"phoneNumber":"13551341345","email":"123456@qq.com","name":"֮֮","power":"businiss","password":"123456"}
dataStore.setDefaultSort("T_ID","desc");


/** ************************查询条件列表**************************** */

function   getSearchFormColumn(columnNumber){
           var   searchFormColumn  = new Array();
           if(columnNumber  == 1){
                 var  book_type_code  = {
                          xtype      :  'textfield',
                          anchor     :  '98%',
                          fieldLabel :  '书籍类型编号',
                          name       :  'book_type_code'
                 }; 
                 searchFormColumn.push(book_type_code);
           }
           else if(columnNumber   == 2){
                 var  book_type_name  = {
                          xtype      :   'textfield',
                          anchor     :   '98%',
                          fieldLabel :   '书籍类型名称',
                          name       :   'book_type_name'
                 };
                 searchFormColumn.push(book_type_name);
           }
           return   searchFormColumn;
}

/** ************************显示数据列表**************************** */

var PAGESIZE = Math.floor((Ext.getBody().getHeight()-220)/21);// 每页显示条数
var sm = new Ext.grid.CheckboxSelectionModel();



function operatorColRender (value , cellmeta , record , rowIndex , columnIndex , store) {
	var show="&nbsp;&nbsp;<a href='javascript:showWin(\"" + rowIndex + "\")'>编辑</a>";
	var del="&nbsp;&nbsp;<a href='javascript:singleDelBookType()'>删除</a>";
	var restore="&nbsp;&nbsp;<a href='javascript:restoreBookType()'><font color='red'>恢复</font></a>";
	                     if((record.data.bookTypeState) == 0){
		                    return show + del 
		                  }
		                 if((record.data.bookTypeState) == 1){
		                     return restore
		                 }
}

/**

function getPbar() {
	var pbar = new Ext.ux.MyPagingToolbar({
				id 			: 'myToolbar',
				pageSize	: PAGESIZE,
				store 		: dataStore,
				displayInfo : true,
				emptyMsg 	: "没有找到任何记录！"
			});
	return pbar;
}
*/

//'id','createTime','phoneNumber','email','name'
function getDataGridColumns() {   // 获取查询页面列表元素
	
	var t_id = {
	    header 		: "编号",
		dataIndex   :'id',
		sortable    : true
	};
	var t_name = {
		 header 	: "用户名",
		dataIndex   :'name',
//		hidden		: true,
		sortable    : true
		
	};
	var t_code = {
		header 		: "注册时间",
		dataIndex 	: 'createTime',
		sortable 	: true
	};
	var t_phone = {
		header 		: "电话号码",
		dataIndex 	: 'phoneNumber',
		sortable 	: true
	};
	var t_desc = {
		header 		: "邮箱",
		dataIndex 	: 'email',
		sortable 	: true
	};
/*	var t_state = {
	    header 		: "状态",
		dataIndex 	: 'bookTypeState',
		sortable 	: true,
		renderer    : function(value , cellmeta , record , rowIndex , columnIndex , store){
		                 var  state = "";
		                 if((record.data.bookTypeState) == 0){
		                      state = "正常";
		                 }
		                 if((record.data.bookTypeState) == 1){
		                      state = "<font color='red'>已删除</font>"
		                 }
		                 return state;
		                 }
	}*/
	
	var operatorColumn = {
		header 		: "操作",
		dataIndex 	: 'discussid',
		width 		: 120,
		renderer 	: operatorColRender,
		sortable 	: false
	};
	var dataColumns = new Array();
	
	dataColumns.push(sm);
	dataColumns.push(t_id);
	dataColumns.push(t_code);
	dataColumns.push(t_name);
	dataColumns.push(t_desc);
	dataColumns.push(t_phone);
	//dataColumns.push(t_state);
	dataColumns.push(operatorColumn);

	return dataColumns;
}


/** ************************增加数据列表布局**************************** */

function  getAddFormItems(columnNumber){
	
	var   addFormItemsArray = new Array();
	 if(columnNumber == "1"){
	   var nameTypeCode = {
			xtype         : 'textfield',
			name          : 'name',
			allowBlank    : false,
			msgTarget     : 'side',
			minLength     : 8,
			minText       : '最少输入8位字符',
			maxLength     : 15,
			maxText       : '最多输入15位字符',
			fieldLabel    : '用户名<font color="red">*</font>'
			//anchor        : '99%'
		};
	   var emailCode = {
			xtype         : 'textfield',
			name          : 'email',
			allowBlank    : false,
			msgTarget     : 'side',
			minLength     : 8,
			minText       : '最少输入8位字符',
			maxLength     : 15,
			maxText       : '最多输入15位字符',
			fieldLabel    : '邮箱<font color="red">*</font>'
			//anchor        : '99%'
		};
	     addFormItemsArray.push(nameTypeCode);
	     addFormItemsArray.push(emailCode);
	     //addFormItemsArray.push(bookTypeCode);
	      }
	 if(columnNumber == "2"){
	   var passwordTypeName = {
			xtype         : 'textfield',
			name          : 'password',
			allowBlank    : false,
			inputType	  : 'password',
			msgTarget     : 'side',
			fieldLabel    : '密码<font color="red">*</font>'
			//anchor        : '99%'
		};
	   var phoneTypeName = {
			xtype         : 'textfield',
			name          : 'phone',
			allowBlank    : false,
			msgTarget     : 'side',
			fieldLabel    : '电话<font color="red">*</font>'
			//anchor        : '99%'
		};
	     addFormItemsArray.push(passwordTypeName);
	     addFormItemsArray.push(phoneTypeName);
	      }
	 if(columnNumber == "3"){
	   var birthdayTypeDesc = {
			xtype         : 'datefield',
			name          : 'birthday',
			format		  : 'Y-m-d',
			grow          : true,
			fieldLabel    : '生日',
			anchor        : '90%'
		};
	   var typeTypeDesc = {
			xtype        : 'combo',
			store         : new Ext.data.SimpleStore( {
			fields        : [ "key", "value" ],
		    data          : [[ '0', '有效' ],[ '1', '无效' ]] }),
			valueField    : "key",
			displayField  : "value",
			mode          : 'local',
			forceSelection: true,
			hiddenName    : 'type',
			editable      : false,
			triggerAction : 'all',
			fieldLabel    : '状态<font color="red">*</font>',
			name          : 'state',
			anchor        : '90%'

		};
	     addFormItemsArray.push(birthdayTypeDesc);
	     addFormItemsArray.push(typeTypeDesc);
	      }
	 return  addFormItemsArray;
}

/** ************************编辑数据列表**************************** */
function getShowFormItemes(data,columnNumber){
	
	
	 var   showFormItemsArray = new Array();
	 if(columnNumber == "1"){
	   var bookTypeCode = {
			xtype         : 'textfield',
			name          : 'bookTypeCode',
			allowBlank    : false,
			msgTarget     : 'side',
			minLength     : 8,
			minText       : '最少输入8位字符',
			maxLength     : 15,
			maxText       : '最多输入15位字符',
			fieldLabel    : '商品类型编号<font color="red">*</font>',
			value         : data.bookTypeCode
			//anchor        : '99%'
		};
	     showFormItemsArray.push(bookTypeCode);
	      }
	 if(columnNumber == "2"){
	   var bookTypeName = {
			xtype         : 'textfield',
			name          : 'bookTypeName',
			allowBlank    : false,
			msgTarget     : 'side',
			fieldLabel    : '商品类型名称<font color="red">*</font>',
			value         : data.bookTypeName
			//anchor        : '99%'
		};
	     showFormItemsArray.push(bookTypeName);
	      }
	 if(columnNumber == "3"){
	   var bookTypeDesc = {
			xtype         : 'textarea',
			name          : 'bookTypeDesc',
			grow          : true,
			fieldLabel    : '商品类型描述',
			anchor        : '90%',
			value         : data.bookTypeDesc
		};
	     showFormItemsArray.push(bookTypeDesc);
	      }
	 return  showFormItemsArray;
}
